/**
*add by cjj 销售品模板数据回显
*/
const temRewrite = {
    RewObject: (data, objArr) => {
        let mainOfferInsts = data.mainOfferInsts;
        for (let key in objArr) {
            let item = objArr[key];
            for (let i = 0; i < mainOfferInsts.length; i++) {
                //多产品选择时，外面套一层productID判断
                if (item.tableName == 'ORDER_ITEM') {
                    item.value = mainOfferInsts[i][item.colId]
                }
                if (item.tableName == 'ORDER_ITEM_ATTR') {
                    mainOfferInsts[i][item.tableName].forEach(m => {
                        if (m.attrId == item.colId) {
                            item.value = m.attrValue;
                        }
                    });
                }
                if (item.tableName == 'ORDER_CONTACT_INFO') {
                    mainOfferInsts[i][item.tableName].forEach(m => {
                        if (m.contactType == "6" && item.attrRoleCd == "100") {
                            item.value = m[item.colId];
                        }
                        if (m.contactType == "7" && item.attrRoleCd == "200") {
                            item.value = m[item.colId];
                        }
                    });
                }
                if (item.tableName == 'ORDER_ITEM_FILE') {
                    mainOfferInsts[i][item.tableName].forEach(m => {
                        item.value = m[item.colId];
                    });
                }
                if (item.tableName == 'ACCT_ITEM_ORG') {
                    mainOfferInsts[i][item.tableName].forEach(m => {
                        if (m.chargeOrgCd == item.attrRoleCd) {
                            item.value = m[item.colId];
                            if (item.tableName == 'ACCT_ITEM') {
                                m[item.tableName].forEach(n => {
                                    if (item.colId == 'AMOUNT') {
                                        item.value = n.amount;
                                    } else {
                                        item.value = n[item.colId];
                                    }
                                })
                            }
                        }
                        if (m.chargeOrgCd == '0' && !item.attrRoleCd) {
                            item.value = m[item.colId];
                            if (item.tableName == 'ACCT_ITEM') {
                                m[item.tableName].forEach(n => {
                                    if (item.colId == 'AMOUNT') {
                                        item.value = n.amount;
                                    } else {
                                        item.value = n[item.colId];
                                    }
                                })
                            }
                        }
                    });
                }
            }
        }
        return objArr;
    },



};

export default temRewrite;
